﻿Imports DAO
Imports DTO

Public Class KhachHang_BUS

    Public Shared Function ThemKhachHang(ByVal khachhang As KhachHang_DTO) As Integer
        Dim sql As String = String.Format("select MaKH from KhachHang where CMND = '{0}'", khachhang.CMND)
        Dim obj As Object = DataProvider.ExcuteScalar(sql)
        If obj = Nothing Then
            Dim flag As Integer
            flag = KhachHang_DAO.ThemKhachHang(khachhang)
            Return flag
        Else
            Return 0
        End If
    End Function

    Public Shared Function KiemTraKhachHang(ByVal cmnd As Long) As Integer
        Dim tb As DataTable = KhachHang_DAO.LayKhachHang(cmnd)
        Try
            If (tb.Rows(0).IsNull(0) = False) Then
                Dim sql As String = "select SoNoToiDa from ThamSo"
                Dim sonotoida As Double = Double.Parse(DataProvider.ExcuteScalar(sql).ToString())
                Dim sonokh As Double = Double.Parse(tb.Rows(0).Item(6).ToString())
                If sonokh <= sonotoida Then
                    Return tb.Rows(0).Item(0).ToString()
                Else
                    Return 1
                End If
            End If
        Catch ex As Exception
            Return 0
        End Try
    End Function


    Public Function TraCuuKhachHang(ByVal KH_CRT As KhachHang_CRT) As DataTable
        Dim dt As DataTable
        dt = KhachHang_DAO.TraCuuKhachHang(KH_CRT)
        Return dt
    End Function

#Region "Load Danh sách khách hàng"
    Public Shared Function DanhSachKhachHang() As DataTable
        Return KhachHang_DAO.DanhSachKhachHang()
    End Function
#End Region

    Public Shared Function BaoCao(ByVal thangbaocao As Integer) As DataTable
        Return KhachHang_DAO.BaoCao(thangbaocao)
    End Function

End Class
